package heartbeat

import (
	"ones-objects/lib/mq"
	"ones-objects/config"
	"time"
)

func StartHeartBeat()  {
	//主要是将当前服务的状态发送给apiservers，确保服务可用
	conf := mq.RabbitConf{
		Dsn: config.GetString(config.RABBITMQ_DSN),
		Exchange: config.GetStringDef(config.RABBITMQ_EXCHANGE_OBJECT, config.STR_EMPTY),
		Queue: config.GetString(config.RABBITMQ_QUEUE_OBJECT),
	}

	//创建mq的连接
	mq := mq.New(conf)
	defer mq.Close()

	//当前服务器的连接url
	content := config.GetString(config.DATAS_API_LISTENER)
	for  {
		mq.Publish(config.OBJECTSERVERS, content)
		time.Sleep(time.Second * 5)
	}
}
